package com.ssm.service.impl;

import com.ssm.dao.IPermissionDao;
import com.ssm.dao.IRoleDao;
import com.ssm.domain.Permission;
import com.ssm.domain.Role;
import com.ssm.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class PermissionImpl implements IPermissionService {

    @Autowired
    private IPermissionDao permissionDao;

    @Autowired
    private IRoleDao roleDao;

    @Override
    public List<Permission> findPermissionByRoleId(String roleId) throws Exception {
        return permissionDao.findPermissionByRoleId(roleId);
    }

    @Override
    public List<Permission> findAll() {
        return permissionDao.findAll();
    }

    @Override
    public Permission findById(String permissionId) {
        return permissionDao.findById(permissionId);
    }

    @Override
    public List<Role> findOtherRoleById(String permissionId) {
        return roleDao.findOtherRolesByPermissionId(permissionId);
    }

    @Override
    public void save(String permissionId, String[] roleIds) {
        for(String roleId : roleIds){
            permissionDao.save(permissionId, roleId);
        }
    }
}
